package chainOfResponsibility;

import gameBasics.GameObject;
import tank.EnemyTank;
import tank.MainTank;

public class MTankETankCollider implements Collider{

    /**
     * 主坦克与敌对坦克碰撞
     * @param o1 主坦克对象
     * @param o2 敌对坦克对象
     */
    @Override
    public boolean collide(GameObject o1, GameObject o2) {
        if(o1 instanceof MainTank mainTank && o2 instanceof EnemyTank enemyTank){
            collideWith(mainTank, enemyTank);
        } else if (o1 instanceof EnemyTank && o2 instanceof MainTank) {
            collide(o2, o1);
        }

        return true;
    }

    /**
     * 主坦克与敌对坦克的碰撞检测
     * @param mainTank 主坦克对象
     * @param enemyTank 敌对坦克对象
     */
    private void collideWith(MainTank mainTank, EnemyTank enemyTank) {
        mainTank.gameObjectCheck(enemyTank);
    }

}
